require "base/operation.rb"

class SqlExprOperation < Operation

	condition do |context|
		context.symbol(:sqlbool_expr) ? 1 : nil
	end

	def sqlexpr_ins( pattern )
		framework.instanciate("base/blind/sqlexpr_eval", {:blind_sql_pattern => pattern} )
	end

	def search_ins()

#		logger.debug Locale.sql_eval_expr_bool( sqlbool_expr )

		ins = nil

		framework.run_group( :blind_sql_pattern ) do |pattern|
			tmp_ins = sqlexpr_ins( pattern )
			if tmp_ins.good then
				logger.info "test acertado con pattern: #{pattern}"
				ins = tmp_ins
				break
			else
				logger.debug "Test de patten: #{pattern} fallido"
			end
		end


		unless ins
			logger.error Locale.failed_to_instatiate_module("base/blind/sqlexpr_eval")
		end

		ins
	end

	def run(context)
		sqlbool_expr = context.symbol(:sqlbool_expr)
		ins = search_ins()
		if ins
			logger.info Locale.evaluating_bool_expression( sqlbool_expr )
			logger.info Locale.evaluating_bool_expression_result( ins.put(sqlbool_expr) ? true:false )
		end
		
	end
end
